package com.zy.vod.sdk;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.zy.vod.util.AliyunVodSDKUtil;

import java.util.List;
/*获取播放地址*/
public class AliyunVodSDKAddress {

    //账号AccessKey信息请填写(必选)
    private static String access_key_id = "LTAI4FeAFe3n8r87buAjKCLE";
    //账号AccessKey信息请填写(必选)
    private static String access_key_secret = "vP2g6zLy0mEtLSGFfDaFametAEJ0N3";


    /*获取播放地址函数*/
    //   id:39940d43e2c74826b178383e0d832d37
    //    id:1c8776546df24106807c7a74c215f534
    public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
        GetPlayInfoRequest request = new GetPlayInfoRequest();
//        request.setVideoId("1c8776546df24106807c7a74c215f534");
        request.setVideoId("5e4781f8963e41afa29ae12f6c79a539");
        return client.getAcsResponse(request);
    }
    /*以下为调用示例*/
    public static void main(String[] argv) throws Exception{

        DefaultAcsClient client = AliyunVodSDKUtil.initVodClient(access_key_id, access_key_secret);

        GetPlayInfoResponse response = new GetPlayInfoResponse();
        try {
            response = getPlayInfo(client);
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }
}
